package com.ruoyi.web.controller.app;

import com.ruoyi.app.domain.AppTravelGuide;
import com.ruoyi.app.service.IAppTravelGuideService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 攻略Controller
 *
 * @author ruoyi
 * @date 2025-01-12
 */
@RestController
@RequestMapping("/app/guide")
public class AppTravelGuideController extends BaseController
{
    @Autowired
    private IAppTravelGuideService appTravelGuideService;

    /**
     * 查询攻略列表
     */
    @PreAuthorize("@ss.hasPermi('app:guide:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppTravelGuide appTravelGuide)
    {
        startPage();
        List<AppTravelGuide> list = appTravelGuideService.selectAppTravelGuideList(appTravelGuide);
        return getDataTable(list);
    }

    /**
     * 导出攻略列表
     */
    @PreAuthorize("@ss.hasPermi('app:guide:export')")
    @Log(title = "攻略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppTravelGuide appTravelGuide)
    {
        List<AppTravelGuide> list = appTravelGuideService.selectAppTravelGuideList(appTravelGuide);
        ExcelUtil<AppTravelGuide> util = new ExcelUtil<AppTravelGuide>(AppTravelGuide.class);
        util.exportExcel(response, list, "攻略数据");
    }

    /**
     * 获取攻略详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:guide:query')")
    @GetMapping(value = "/{guideId}")
    public AjaxResult getInfo(@PathVariable("guideId") Long guideId)
    {
        return success(appTravelGuideService.selectAppTravelGuideByGuideId(guideId));
    }

    /**
     * 新增攻略
     */
    @PreAuthorize("@ss.hasPermi('app:guide:add')")
    @Log(title = "攻略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppTravelGuide appTravelGuide)
    {
        return toAjax(appTravelGuideService.insertAppTravelGuide(appTravelGuide));
    }

    /**
     * 修改攻略
     */
    @PreAuthorize("@ss.hasPermi('app:guide:edit')")
    @Log(title = "攻略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppTravelGuide appTravelGuide)
    {
        return toAjax(appTravelGuideService.updateAppTravelGuide(appTravelGuide));
    }

    /**
     * 删除攻略
     */
    @PreAuthorize("@ss.hasPermi('app:guide:remove')")
    @Log(title = "攻略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guideIds}")
    public AjaxResult remove(@PathVariable Long[] guideIds)
    {
        return toAjax(appTravelGuideService.deleteAppTravelGuideByGuideIds(guideIds));
    }
}
